<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<script type="text/javascript">
$(function() {
     parent.$.messager.progress('close');

     $('#form').form({
         url : contextPath+"/posts/addPosts.action",
         onSubmit : function() {
             parent.$.messager.progress({
                 title : var_alert_title,
                 text : var_data_processing
             });
             //检查Form参数合法性,返回false不提交
            if(!checkForm()){
                parent.$.messager.progress('close');
                 return false;
             }
         },
         success : function(data) {
             parent.$.messager.progress('close');
             data = JSON.parse(data);
             if(data && "success" == data.result){
            	 parent.$.messager.alert(var_alert_title, data.msg, 'info');
            	 parent.$.modalDialog.handler.dialog('close');
           	     parent.$.modalDialog.openner_dataGrid.datagrid('reload');
             } else {
                 parent.$.messager.alert(var_common_error, data.msg, 'error');
             }
         }
     });
});

function checkForm(){
	var isValid = true;
	var checkPostsUrl = contextPath + "/posts/checkPosts.action";
	
	var postNum = $("#form").find("[name='postNum']").validatebox({
	    required: true,
	    validType:['length[1,30]','remoteValid[\''+checkPostsUrl+'\',\'postNum\',\'<s:text name="erp.business.posts.main.tempisexisted"></s:text>\']']
	});
	isValid = isValid && postNum.validatebox('isValid');
	
	var postName = $("#form").find("[name='postName']").validatebox({
	    required: true
	});
	isValid = isValid && postName.validatebox('isValid');

	return isValid;
}
</script>
<div id="add-edit-dialog">
        <div class="p5">
            <form id="form" name="form" action="" method="post">
                <table class="tablewidth1">
                	<tr>
                		<td align="right">
                			<s:text name="erp.system.posts.postnum"></s:text>：
                		</td>
                		<td align="left">
                			<input id="postNum" name="postNum" class="span2" type="text" value=""/>
                		</td>
                		<td align="right">
                			<s:text name="erp.system.posts.postname"></s:text>：
                		</td>
                		<td align="left">
                			<input id="postName" name="postName" class="span2"  type="text" value=""/>
                		</td>
                	</tr>
                	<tr>
                		<td align="right">
                			<s:text name="erp.system.posts.deptId"></s:text>：
                		</td>
                		<td align="left" colspan="3">
                			<select id="deptId" name="deptId">
                				<option value="">-选择-</option>
                				<option value="1">研发部</option>
                				<option value="2">行政</option>
                			</select>
                		</td>
                	</tr>
                	<tr>
        			<td align="right">
        				描述信息：
        			</td>
        			<td colspan="3">
        				<textarea id="description" name="description" class="" style="height: 80px;overflow: auto;line-height: 18px;width: 455px;"></textarea>
        			</td>
        		</tr>
                </table>
               
                <div class="fn-clear"></div>
            </form>
        </div>
    </div> 